package demo;

import java.util.Arrays;

class Student {
    public String name;
    public int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}

public class Test {
    public static void main(String[] args) {
/*        Student[] students=new Student[3];
        students[0] =new Student("zhangsan",4);
        students[1] =new Student("lisi",5);
        students[2] =new Student("wangwu",2);
        System.out.println(Arrays.toString(students));   //  代码报错！  Student cannot be cast to class java.lang.Comparable
        Arrays.sort(students);//没有指定用什么数据进行排序   //ClassCastException类型转换异常  没有实现comparable接口
        System.out.println(Arrays.toString(students));*/

        Student student1=new Student("zhangsan",4);
        Student student2=new Student("lisi",6);

        //年龄比较器
        AgeComparator ageComparator=new AgeComparator();
        int ret=ageComparator.compare(student1,student2);
        System.out.println(ret);
        //名字比较器
        NameComparator nameComparator=new NameComparator();
        int ret2=nameComparator.compare(student1,student2);
        System.out.println(ret2);
    }





}
